package com.zeroup.auto.assists.step.unify;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;

import androidx.annotation.NonNull;

import com.ven.assists.Assists;
import com.ven.assists.stepper.Step;
import com.ven.assists.stepper.StepCollector;
import com.ven.assists.stepper.StepData;
import com.zeroup.auto.assists.DouYinBaseStep;
import com.zeroup.auto.assists.next.StepBeanData;
import com.zeroup.auto.utils.AssistsUtils;

import java.util.List;

public class ClipStep extends DouYinBaseStep {
    @Override
    public void onImpl(@NonNull StepCollector stepCollector) {
        stepCollector.next(1,false,(i,c)->{
            Object serviceData = AssistsUtils.getServiceData(i.getData());
            if(serviceData==null){
                return AssistsUtils.nextStep(i.getData());
            }
            List<AccessibilityNodeInfo> infoList = null;
            if(serviceData instanceof StepBeanData){
                StepBeanData stepBeanData = (StepBeanData)serviceData;
                ClipData clip = ClipData.newPlainText(System.currentTimeMillis()+"", stepBeanData.getDataValue());
                ClipboardManager clipboardManager = (ClipboardManager) Assists.getService().getSystemService(Context.CLIPBOARD_SERVICE);
                clipboardManager.setPrimaryClip(clip);
                Log.d("UnifyStep===>","执行了剪切板事件");
                return AssistsUtils.nextStep(i.getData());
            }
            return Step.Companion.getRepeat();
        });
    }
}
